package com.liu.sportplat.controller;

import com.alibaba.fastjson.JSON;
import com.liu.sportplat.bean.MainMenu;
import com.liu.sportplat.dao.MenuMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
public class MenuController {
    @Autowired
    MenuMapping menuMapping;

    @RequestMapping("/menus")
    public String getAllMenus(){
        System.out.println("访问主页成功！");
        HashMap<String, Object> data = new HashMap<>();
        List<MainMenu> menus = menuMapping.getMenus();
        if(menus!=null){
            //200 成功 404 失败
            data.put("menus",menus);
            data.put("flag",200);
        }else {
            data.put("flag",404);
        }
        //转为json格式，返回给前端
        String jsonString = JSON.toJSONString(data);
        return jsonString;
    }
}
